<template>
  <section v-loading="loading" class="cms-body">
    <div class="cms-list-header flex-between">
      <div>
        <el-select v-model="params.status" @change="goQuery()">
          <el-option label="状态" value=""></el-option>
          <el-option label="禁用" value="0"></el-option>
          <el-option label="启用" value="1"></el-option>
          <el-option label="锁定" value="2"></el-option>
        </el-select>
        <el-select v-model="params.blackStatus" @change="goQuery()">
          <el-option label="名单状态" value=""></el-option>
          <el-option label="白名单" value="0"></el-option>
          <el-option label="黑名单" value="1"></el-option>
        </el-select>
        <cms-input label="姓名" v-model="params.userName"></cms-input>
        <cms-input label="昵称" v-model="params.nickName"></cms-input>
        <cms-input label="手机号" v-model="params.mobile"></cms-input>
        <cms-input label="电子邮箱" v-model="params.email"></cms-input>
        <el-button @click="goQuery()">查询</el-button>
      </div>
    </div>
    <!-- 表格 -->
    <el-table :data="tableData" stripe style="width: 100%" @selection-change="checkIds">

      <el-table-column type="selection" width="30" align="center"></el-table-column>

      <el-table-column prop="id" label="ID" width="150" align="center"></el-table-column>

      <el-table-column prop="userName" label="姓名" align="left">
      </el-table-column>

      <el-table-column prop="nickName" label="昵称" align="left"></el-table-column>

      <el-table-column prop="mobile" label="手机号" width="100" align="center">
        <div slot-scope="scope">
          <span v-if="scope.row.mobile.length>0 && scope.row.areaCode.length>0">{{scope.row.areaCode+' '+scope.row.mobile }} </span>
          <span v-else>{{scope.row.mobile }} </span>
        </div>
      </el-table-column>

      <el-table-column prop="email" label="电子邮箱" width="165" align="center"></el-table-column>

      <el-table-column prop="birthday" label="出生日期" width="90" align="center"></el-table-column>
      <el-table-column prop="isBlack" label="黑名单" width="60" align="center">
        <div slot-scope="scope">
          <span v-if="scope.row.isBlack">黑名单</span>
          <span v-else>白名单</span>
        </div>
      </el-table-column>

      <el-table-column prop="registerTime" label="注册时间" width="120" align="center"></el-table-column>

      <el-table-column prop="status" label="状态" width="50" align="center">
        <div slot-scope="scope">
          <span v-if="scope.row.status==1">启用</span>
          <span v-if="scope.row.status==0">禁用</span>
        </div>
      </el-table-column>

      <el-table-column prop="name" label="操作" align="center" width="90">
        <div slot-scope="scope">
          <cms-button type="edit" @click.native="routerLink('/appUser/update','update',scope.row.id)"
                      v-perms="'/appUser/update'"></cms-button>
          <cms-button type="view" @click.native="lookAccount(scope.row.id)"
                      v-perms="'/appUser/lookAccount'"></cms-button>
        </div>
      </el-table-column>

    </el-table>
    <!-- 表格底部 -->
    <div class="cms-list-footer">
      <div class="cms-left">
        <el-button :disabled="disabled" @click="batchAddBlackList($api.appUserAddBlack,ids)"
                   v-perms="'/appUser/addBlackList'">批量加入黑名单
        </el-button>
        <el-button :disabled="disabled" @click="batchRemoveBlackList($api.appUserRemoveBlack,ids)"
                   v-perms="'/appUser/removeBlackList'">批量移除黑名单
        </el-button>
      </div>
      <!-- 分页组件 -->
      <cms-pagination :total="total" @change="getPages"></cms-pagination>
    </div>
    <el-drawer title="用户账号" :visible.sync="showDrawerTable" direction="rtl" size="80%" @close="initDrawerParams()">
      <el-table :data="drawerTableData" stripe @selection-change="checkIdsAndStatus" v-loading="loading">
        <el-table-column type="selection" width="50" align="center"></el-table-column>
        <el-table-column label="账号Id" prop="accountId" align="left"></el-table-column>
        <el-table-column label="账号" prop="account" align="left"></el-table-column>
        <el-table-column label="账号类型" prop="accountType" align="center" width="130">
          <div slot-scope="scope">
            <span v-if="scope.row.accountType=='MOBILE'">手机号码</span>
            <span v-else-if="scope.row.accountType=='EMAIL'">邮箱</span>
            <span v-else-if="scope.row.accountType=='FACEBOOK'">FaceBooK</span>
            <span v-else-if="scope.row.accountType=='WEIXIN'">微信</span>
          </div>
        </el-table-column>
        <el-table-column label="创建日期" prop="createTime" align="center" width="130"></el-table-column>
      </el-table>
      <!-- 表格底部 -->
      <div class="cms-list-footer" style="padding-bottom:100px;">
        <div class="cms-left"></div>
        <cms-pagination :total="drawerTotal" @change="getDrawerPages"></cms-pagination>
      </div>
    </el-drawer>
  </section>
</template>

<script>
  import listMixins from '@/mixins/list'
  import drawerListMixins from '@/mixins/drawerList'

  export default {
    mixins: [listMixins, drawerListMixins],
    data() {
      return {
        params: {//只需要业务参数
          pageNo: 1,
          pageSize: 10,
          userName: '',
          email: '',
          status: '',
          blackStatus: '',
          userId: ''
        },
        showDrawerTable: false,
        userId: ""
      };
    },
    methods: {
      goQuery() {
        this.getTableData(this.params);
      },
      lookAccount(userId) {
        this.showDrawerTable = true;
        this.userId = userId;
        let params = {'userId': userId}
        this.initDrawerTableData(this.$api.appAccountList, params) //请求列表
      },
      initDrawerTableData(url, drawerParams) {
        this.drawerParams = drawerParams;
        this.drawerListUrl = url;
        this.getDrawerTableData(drawerParams)
      },
      batchAddBlackList(url, ids) {
        this.$confirm('是否加入黑名单？', '警告', {type: "error"}).then(mes => {
          this.$http.post(url, {ids: ids}).then(res => {
            console.log(res);
            if (res.code == "200") {
              this.successMessage('加入成功');
              this.getTableData(this.params);
            }
          });
        }).catch(error => {
          console.log(error);
        });
      },
      batchRemoveBlackList(url, ids) {
        this.$confirm('是否移除黑名单？', '警告', {type: "error"}).then(mes => {
          this.$http.post(url, {ids: ids}).then(res => {
            console.log(res);
            if (res.code == "200") {
              this.successMessage('移除成功');
              this.getTableData(this.params);
            }
          });
        }).catch(error => {
          console.log(error);
        });
      }
    },
    created() {
      if (this.$route.query.id != '0') {
        this.params.userId = this.$route.query.id;
      }
      this.initTableData(this.$api.appUserList, this.params);
    }
  };
</script>

<style>

</style>
